<template>
  <div>
    <el-table
      :data="list"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      default-expand-all
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="title" label="图片名称" sortable width="180">
      </el-table-column>
      <el-table-column prop="img" label="图片">
        <template slot-scope="scoped">
          <div>
            <img :src="$pre + scoped.row.img" alt="" />
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scoped">
          <div>
            <el-button type="success" v-if="scoped.row.status == 1"
              >启用</el-button
            >
            <el-button type="info" v-else>禁用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scoped">
          <div>
            <el-button type="success" @click="update(scoped.row.id)"
              >编辑</el-button
            >
            <v-del @del="del(scoped.row.id)"></v-del>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { bannerdelete } from "../../../request/api.js";
import { mapGetters, mapActions } from "vuex";
import { successAlert, warningAlert } from "../../../utils/alert.js";
export default {
  data() {
    return {};
  },

  methods: {
    ...mapActions({
      asyncChangeList: "banner/asyncChangeList",
    }),
    //删除
    del(id) {
      bannerdelete({ id: id }).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          this.asyncChangeList();
        } else {
          warningAlert(res.data.msg);
        }
      });
    },
    //编辑
    update(id) {
      this.$emit("update", id);
    },
  },
  computed: {
    ...mapGetters({
      list: "banner/list",
    }),
  },

  mounted() {
    this.asyncChangeList();
  },
};
</script>

<style  scoped>
img {
  width: 100px;
  height: 100px;
}
</style>